//****************************************************************
//* Copyright (c) 2008 Ford Motor Company. All Rights Reserved.
//*
//* $$Workfile:   EconomicIndexStatusForm.java  $$
//* $$Revision:   1.1  $$
//* $$Author:   JLOPE262  $$
//* $$Date:   Nov 21 2008 14:27:06  $$
//*
//*****************************************************************
package ar.com.ford.it.fullEconomics.view.form;

import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.util.MessageResources;
import org.apache.struts.validator.ValidatorForm;

public class EconomicIndexStatusForm extends ValidatorForm {
    private String section;
    private String year;
    private Collection updateStatusCol;
    private Collection economicSources;
    private String economicSourceSel;
    private String monthSelected;
    private String econSourceNumberSelected;
    private String econValueTypeSelected;
    
    public String getEconValueTypeSelected() {
        return econValueTypeSelected;
    }

    public void setEconValueTypeSelected(String econValueTypeSelected) {
        this.econValueTypeSelected = econValueTypeSelected;
    }

    public void resetForm() {
        this.section = null;
        this.year = null;
        this.updateStatusCol = null;
        this.economicSources = null;
        this.economicSourceSel = null;
    }
    
    public void cleanFindFields() {
        this.economicSourceSel = null;
        this.year = null;
    }

    public String getEconSourceNumberSelected() {
        return econSourceNumberSelected;
    }

    public void setEconSourceNumberSelected(String econSourceNumberSelected) {
        this.econSourceNumberSelected = econSourceNumberSelected;
    }

    public String getMonthSelected() {
        return monthSelected;
    }

    public void setMonthSelected(String monthSelected) {
        this.monthSelected = monthSelected;
    }    
    
    public String getEconomicSourceSel() {
        return economicSourceSel;
    }

    public void setEconomicSourceSel(String economicSourceSel) {
        this.economicSourceSel = economicSourceSel;
    }

    public Collection getEconomicSources() {
        return economicSources;
    }

    public void setEconomicSources(Collection economicSources) {
        this.economicSources = economicSources;
    }

    public String getSection() {
        return section;
    }

    public void setSection(String section) {
        this.section = section;
    }

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }

    public Collection getUpdateStatusCol() {
        return updateStatusCol;
    }

    public void setUpdateStatusCol(Collection updateStatusCol) {
        this.updateStatusCol = updateStatusCol;
    }
    
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors ae = new ActionErrors();        
        MessageResources resources = (MessageResources) request.getAttribute(org.apache.struts.Globals.MESSAGES_KEY);
                
        if ("find".equalsIgnoreCase(this.getSection())) {
            if (StringUtils.isNotBlank(this.getYear())) {
                if (this.getYear().matches("[0-9]+")) {
                    if (this.getYear().length() != 4) {
                        this.setYear(null);
                        ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.exactLength", resources.getMessage("label.year"), 4));
                    }
                } else {
                    this.setYear(null);
                    ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.integergtzero", resources.getMessage("label.year")));
                }
            } else {
                ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.required", resources.getMessage("label.year")));
            }
        }
                
        return ae;
    }
}
